<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of admin_m
 *
 * @author QUYET
 */
class admin_m extends CI_Model {
    var $language = 1;
    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->library('pagination');
        if($this->session->userdata('lang')=='en') $this->language = 2;
    }
    
    function get_invoices($status=3,$per_page=10,$off_set=0){
        $this->db->from('ots_invoice');
        if($status<3){
            $this->db->where('status',$status);
        }
        $this->db->order_by('invoice_date','DESC');
        $this->db->limit($per_page,$off_set);
        return $this->db->get()->result_array();
    }
    function count_invoices($status=3){
        $this->db->from('ots_invoice');
        if($status<3){
            $this->db->where('status',$status);
        }
        return count($this->db->get()->result_array());
    }
    
    function get_invoice_details($id_invoice){
        $this->db->select('ots_invoice.email,ots_serial.serial_number,ots_ticket_lang.ticket_name,ots_ticket.price,ots_invoice_detail.serial_id');
        $this->db->from('ots_invoice');
        $this->db->join('ots_invoice_detail','ots_invoice.id = ots_invoice_detail.invoice_id');
        $this->db->join('ots_serial','ots_invoice_detail.serial_id = ots_serial.id');
        $this->db->join('ots_ticket_serial','ots_serial.id = ots_ticket_serial.serial_id');
        $this->db->join('ots_ticket','ots_ticket_serial.ticket_id = ots_ticket.id');
        $this->db->join('ots_ticket_lang','ots_ticket_lang.id_ticket = ots_ticket.id');
        $this->db->where('ots_invoice_detail.invoice_id',$id_invoice);
        $this->db->where('ots_ticket_lang.id_lang',$this->language);
        return $this->db->get()->result_array();
    }
}

?>
